// Loesung_von_Aufgabe_5.6_2_Schwingkreis_gedaempft

float L = 1; // Induktivität in H
float C = 1; // Kapazität in F
float EF; // Farbwert für das E-Feld
float BF; // Farbwert für das B-Feld
float t; // Zeit
float k = 0.3; // Dämpfungsfaktor

void setup()
{
  size(400, 400);
}

void draw()
{
  background(255);

  // sich ändernde Stärke des E- und B-Feldes
  EF = 255*exp(-k*t)*abs(sin(t/sqrt(L*C)));
  BF = 255*exp(-k*t)*abs(cos(t/sqrt(L*C)));
  t = t + 0.01;

  noStroke();
  // Farbe des E-Feldes
  fill(255, 255-EF, 255-EF);
  rect(90, 183, 86, 45);

  // Farbe des B-Feldes
  fill(255-BF, 255, 255-BF);
  ellipse(300, 200, 70, 140);

  // Spule
  for (float a = 163; a >= 212 || a >= 113; a = a - 5) 
  {
    stroke(0);
    noFill();
    ellipse(299, 65 + a, 30, 10);
  }

  // Kondensator
  fill(0);
  rect(90, 178, 86, 5);
  rect(90, 228, 86, 5);

  // Leiterbahnen
  noFill();
  beginShape();
  vertex(133, 178);
  vertex(133, 78);
  vertex(299, 78);
  vertex(299, 173);
  endShape();

  beginShape();
  vertex(133, 233);
  vertex(133, 315);
  vertex(299, 315);
  vertex(299, 233);
  endShape();
}